#include <iostream>
using namespace std;
#include <string>
#include <algorithm>

void rev(string &str)
{
    reverse(str.begin(), str.end());
    size_t start = 0;
    for (size_t i = 0; i <= str.size(); i++)
    {
        if (i == str.size() || str[i] == ' ')
        {
            reverse(str.begin() + start, str.begin() + i);
            start = i + 1;
        }
    }
}

int main()
{
    string ptr = "l am a student.";
    // reverse(ptr.begin(), ptr.end());
    // cout << "ptr:" << ptr << endl;
    //  int length = ptr.size();

    rev(ptr);
    cout << "ptr:" << ptr << endl;

    return 0;
}
